<?php
/**
 * Created by PhpStorm.
 * User: Deann.wu
 * Date: 2018/3/20 0020
 * Time: 14:35
 */
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Models\TagPost;
use App\Models\Tags;
use App\Models\Types;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;

class TagsController extends Controller{

    public function __construct()
    {
        parent::__construct();
        //标签
        View::share('keyword','');
        //标题
        View::share('title','分类信息');
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author Deann.wu
     * @name 根据分类id获取数据
     */
    public function getList($tag_id){
        //获取分类数据
        $tp_info=Tags::getInfoById($tag_id);
        //筛选数据
        $lists=TagPost::getGoodsByTagsList($tag_id);
        //模块阐述
        $this->modelElaborate('标签：'.$tp_info->name,'标签归档 "'.$tp_info->name.'"','列表','/home/images/main-dm.jpg');
        return view('home.tag.list',compact('lists'));
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author Deann.wu
     * @name 所有标签
     */
    public function getTagsList(){
        //所有标签数据
        $lists=Tags::getListDataAll();
        //拥有该标签的文章数量
        foreach ($lists as $list){
            $list->t_count=TagPost::getCountByTagId($list->id);
        }
        //模块阐述
        $this->modelElaborate('所有标签'," 一屋不扫，何以扫天下。",'标签列表','/home/images/main-dm.jpg');
        return view('home.tag.list_tag',compact('lists'));
    }

}